<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="批量设置" @ok="handleSubmit" width="500px" destroyOnClose>
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { batchSettingSkuStockFormSchema } from './goods.data';
// 声明Emits
const emit = defineEmits(['register', 'success']);

const [registerForm, { resetFields, validate }] = useForm({
  labelWidth: 100,
  schemas: batchSettingSkuStockFormSchema,
  showActionButtonGroup: false
});

const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  await resetFields();
  setModalProps({ confirmLoading: false, canFullscreen: false, draggable: false, height: 300});
});

async function handleSubmit(v) {
  try {
    let values = await validate();
    setModalProps({ confirmLoading: true });
    closeModal();
    emit('success', values);
  } finally {
    setModalProps({ confirmLoading: false });
  }
}
</script>
